package com.sam.im.heiqun.uis.activities;

import android.os.Bundle;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.sam.im.heiqun.R;
import com.sam.im.heiqun.utils.ToolsUtils;
import com.yuyh.library.uis.activitys.BaseSwipeBackActivity;

import butterknife.BindView;
import cmb.pb.util.CMBKeyboardFunc;

public class RechargeZHWebViewActivity extends BaseSwipeBackActivity {

    @BindView(R.id.recharge_web_view)
    WebView webview;

private String payUrl = "" ;
    private WebSettings webSettings;

    @Override
    public int getContentViewId() {
        return R.layout.activity_recharge_web_view;
    }

    @Override
    protected String getTitleText() {
        return getString(R.string.recharge);
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {

        String money = getIntent().getStringExtra("money");
//        Log.i("-----", "initViews: getMyUserId="+ToolsUtils.getMyUserId());
        payUrl = "http://120.27.214.115/user/cmbcpay?uid="+ ToolsUtils.getPhpUid()+"&money="+money;

        // 对WebView进行设置
        WebSettings set = webview.getSettings();
        // 支持JS
        set.setJavaScriptEnabled(true);
        set.setSaveFormData(false);
        set.setSavePassword(false);
        set.setSupportZoom(false);

        //webview.loadUrl(DevUrl);
        LoadUrl();
        webview.setWebViewClient( new  WebViewClient() {
            public   boolean   shouldOverrideUrlLoading(WebView view, String url){
//                Log.i("-----", "initViews: url-url="+url);
                if ("http://yidongyunxinwallet/".equals(url)){//退出到钱包！！！
                    showToast(getResources().getString(R.string.exit_money_to_wal));
                    scrollToFinishActivity();
                    return false;
                }else{
                    // 使用当前的WebView加载页面
                    CMBKeyboardFunc kbFunc = new CMBKeyboardFunc(RechargeZHWebViewActivity.this);
                    if(kbFunc.HandleUrlCall(webview, url) == false)
                    {
                        return super.shouldOverrideUrlLoading(view, url);
                    }
                    else
                    {
                        return true;
                    }
                }


                //view.loadUrl(url);
                //return  true ;
            }
        });
    }


    private void LoadUrl()
    {
        try
        {

            CookieSyncManager.createInstance(RechargeZHWebViewActivity.this.getApplicationContext());
            CookieManager.getInstance().removeAllCookie();
            CookieSyncManager.getInstance().sync();
        }
        catch(Exception e)
        {

        }
        webview.loadUrl(payUrl);
    }

}
